//****************************************************************************
// inputparmetersparser.cpp
// implamentaion of the WinInputParmetersParser class.
//
// Author: Einat Zuker
//****************************************************************************
#include <Windows.h>
#include "inputparmetersparser.h"

//----------------------------------------------------------------------------
// Ctor
// creates a WinInputParmetersParser object.
//
// @param fileName
//		the name of the input file to parse.
//
// @throw InputParmetersParserExepetion
//		if an error occurred in the construction of the object.
//----------------------------------------------------------------------------
WinInputParmetersParser::WinInputParmetersParser(string fileName)
: InputParmetersParser(fileName)
{
	
	char buffer[LARGE_BUFFER_SIZE] = {0};
	if (GetCurrentDirectory(LARGE_BUFFER_SIZE, buffer) > 0)
	{
		//get the absult path to the file - for ini funcations.
		string fullPath = buffer;
		fullPath +=  "\\";
		fullPath += fileName;
		m_FileName = fullPath;
	}
	else
	{
		throw (new InputParmetersParserExepetion("faild to initilez the WinInputParmetersParser"));
	}
}

//****************************************************************************
// general parameters
//****************************************************************************
//----------------------------------------------------------------------------
// GetImprovedColoringOnly
// returns the value of the parameter improvedColoringOnly in the input file.
// note: default return value is true - we want to realy improve the given coloring.
//
// @return bool
//		true - if the parameter value was true
//		false - if not
//----------------------------------------------------------------------------
bool WinInputParmetersParser::GetImprovedColoringOnly()
{
	char buffer[SMALL_BUFFER_SIZE] = {0};
	if (GetPrivateProfileString("general", "improvedColoringOnly", "true", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return (strcmp(buffer, "false") == 0 ? false : true); 
	}

	return true;
}

//****************************************************************************
// permutations parameters
//****************************************************************************
//----------------------------------------------------------------------------
// GetMinPermutationChainLength
// returns the value of the parameter minPermutationChainLength in the input file.
//
// @return int
//		the value of the parameter minPermutationChainLength on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetMinPermutationChainLength()
{
	char buffer[SMALL_BUFFER_SIZE] = {0};
	if (GetPrivateProfileString("permutaions", "minPermutationChainLength", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetIntersectionSize
// returns the value of the parameter intersectionSize in the input file.
//
// @return int
//		the value of the parameter intersectionSize on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetIntersectionSize()
{
	char buffer[SMALL_BUFFER_SIZE] = {0};
	if (GetPrivateProfileString("permutaions", "intersectionSize", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetChainNumber
// returns the value of the parameter chainNumber in the input file.
//
// @return int
//		the value of the parameter chainNumber on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetChainNumber()
{
	char buffer[SMALL_BUFFER_SIZE] = {0};
	if (GetPrivateProfileString("permutaions", "chainNumber", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetPermutationPercent
// returns the value of the parameter permutationPercent in the input file.
//
// @return double
//		the value of the parameter permutationPercent on success
//		-1 on failure.
//----------------------------------------------------------------------------
double WinInputParmetersParser::GetPermutationPercent()
{
	char buffer[SMALL_BUFFER_SIZE] = {0};
	if (GetPrivateProfileString("permutaions", "permutationPercent", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atof(buffer);
	}

	return -1.0;
}

//****************************************************************************
// graphcoloring parameters
//****************************************************************************
//----------------------------------------------------------------------------
// GetNumberOfIterationsForGreedySearch
// returns the value of the parameter numberOfIterationsForGreedySearch 
// in the input file.
//
// @return int
//		the value of the parameter numberOfIterationsForGreedySearch on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetNumberOfIterationsForGreedySearch()
{
	char buffer[SMALL_BUFFER_SIZE] = {0};
	if (GetPrivateProfileString("graphColoring", "numberOfIterationsForGreedySearch", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetBreakingPercentage
// returns the value of the parameter breakingPercentage in the input file.
//
// @return int
//		the value of the parameter breakingPercentage on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetBreakingPercentage()
{
	char buffer[SMALL_BUFFER_SIZE] = {0};
	if (GetPrivateProfileString("graphColoring", "breakingPercentage", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetBreakingIterationsGroupSize
// returns the value of the parameter breakingIterationsGroupSize in the input file.
//
// @return int
//		the value of the parameter breakingIterationsGroupSize on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetBreakingIterationsGroupSize()
{
	char buffer[SMALL_BUFFER_SIZE] = {0};
	if (GetPrivateProfileString("graphColoring", "breakingIterationsGroupSize", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetDropPercent
// returns the value of the parameter dropPercent in the input file.
//
// @return int
//		the value of the parameter dropPercent on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetDropPercent()
{
	char buffer[SMALL_BUFFER_SIZE] = {0};
	if (GetPrivateProfileString("graphColoring", "dropPercent", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetMaxIndexForOptimizations
// returns the value of the parameter maxIndexForOptimizations in the input file.
//
// @return int
//		the value of the parameter maxIndexForOptimizations on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetMaxIndexForOptimizations()
{
	char buffer[SMALL_BUFFER_SIZE] = {0}; 
	if (GetPrivateProfileString("graphColoring", "maxIndexForOptimizations", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetMaxIndexForImprovedGreedy
// returns the value of the parameter maxIndexForImprovedGreedy in the input file.
//
// @return int
//		the value of the parameter maxIndexForImprovedGreedy on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetMaxIndexForImprovedGreedy()
{
	char buffer[SMALL_BUFFER_SIZE] = {0}; 
	if (GetPrivateProfileString("graphColoring", "maxIndexForImprovedGreedy", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetPercentOfVerticesToStartImprovedGreedy
// returns the value of the parameter percentOfVerticesToStartImprovedGreedy 
// in the input file.
//
// @return int
//		the value of the parameter percentOfVerticesToStartImprovedGreedy 
//		on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetPercentOfVerticesToStartImprovedGreedy()
{
	char buffer[SMALL_BUFFER_SIZE] = {0}; 
	if (GetPrivateProfileString("graphColoring", "percentOfVerticesToStartImprovedGreedy", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetPercentOfVerticesToStopImprovedGreedy
// returns the value of the parameter percentOfVerticesToStopImprovedGreedy
// in the input file.
//
// @return int
//		the value of the parameter percentOfVerticesToStopImprovedGreedy 
//		on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetPercentOfVerticesToStopImprovedGreedy()
{
	char buffer[SMALL_BUFFER_SIZE] = {0}; 
	if (GetPrivateProfileString("graphColoring", "percentOfVerticesToStopImprovedGreedy", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetNumberOfPairsInImprovedGreedy
// returns the value of the parameter numberOfPairsInImprovedGreedy
// in the input file.
//
// @return int
//		the value of the parameter numberOfPairsInImprovedGreedy on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetNumberOfPairsInImprovedGreedy()
{
	char buffer[SMALL_BUFFER_SIZE] = {0}; 
	if (GetPrivateProfileString("graphColoring", "numberOfPairsInImprovedGreedy", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetFastMode
// returns the value of the parameter fastMode in the input file.
//
// @return int
//		the value of the parameter fastMode on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetFastMode()
{
	char buffer[SMALL_BUFFER_SIZE] = {0}; 
	if (GetPrivateProfileString("graphColoring", "fastMode", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetDestinationChainSize
// returns the value of the parameter destinationChainSize in the input file.
//
// @return int
//		the value of the parameter destinationChainSize on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetDestinationChainSize()
{
	char buffer[SMALL_BUFFER_SIZE] = {0}; 
	if (GetPrivateProfileString("graphColoring", "destinationChainSize", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetNumberOfIterationsForVertexSearch
// returns the value of the parameter numberOfIterationsForVertexSearch 
// in the input file.
//
// @return int
//		the value of the parameter numberOfIterationsForVertexSearch 
//		on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetNumberOfIterationsForVertexSearch()
{
	char buffer[SMALL_BUFFER_SIZE] = {0}; 
	if (GetPrivateProfileString("graphColoring", "numberOfIterationsForVertexSearch", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}

//----------------------------------------------------------------------------
// GetNumberOfIterationsToFillPermutaionChain
// returns the value of the parameter numberOfIterationsToFillPermutaionChain
// in the input file.
//
// @return int
//		the value of the parameter numberOfIterationsToFillPermutaionChain
//		on success
//		-1 on failure.
//----------------------------------------------------------------------------
int WinInputParmetersParser::GetNumberOfIterationsToFillPermutaionChain()
{
	char buffer[SMALL_BUFFER_SIZE] = {0}; 
	if (GetPrivateProfileString("graphColoring", "numberOfIterationsToFillPermutaionChain", "-1", buffer, SMALL_BUFFER_SIZE, m_FileName.c_str()) > 0)
	{
		return atoi(buffer); 
	}

	return -1;
}